package com.lagou.edu.service.impl;
import com.lagou.edu.annotation.Autowired;
import com.lagou.edu.annotation.Service;
import com.lagou.edu.annotation.Transactional;
import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.dao.impl.JdbcAccountDaoImpl;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.TransferService;
/**
 */
@Service("transferService")
@Transactional
public class TransferServiceImpl implements TransferService {
    //private AccountDao accountDao = new JdbcAccountDaoImpl();
    @Autowired
    private AccountDao accountDao;

    // 提供set方法供外部注入dao层实现类
    public void setAccountDao(AccountDao accountDao){
        this.accountDao = accountDao;
    }
    @Override
    public void transfer(String fromCardNo, String toCardNo, int money)
            throws Exception {
        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);
        from.setMoney(from.getMoney()-money);
        /*System.out.println(1/0);*/
        to.setMoney(to.getMoney()+money);
        accountDao.updateAccountByCardNo(from);
        accountDao.updateAccountByCardNo(to);
    }
}